UNZIP
Section: Misc. Reference Manual Pages (1L)
Updated: 28 Aug 94 (v5.12)
Index
Return to Main Contents
NAME
unzip - list, test and extract compressed files in a ZIP archive
SYNOPSIS
unzip [-Z] [-cflptuvz[abjnoqsCLV$]]
file[.zip] [file(s) ...]
[-x xfile(s) ...] [-d exdir]
DESCRIPTION
unzip will list, test, or extract files from a ZIP archive, commonly
found on MS-DOS systems. The default behavior (with no options) is to extract
into the current directory (and subdirectories below it) all files from the
specified ZIP archive. A companion program, zip(1L), creates ZIP
archives; both programs are compatible with archives created by PKWARE's
PKZIP and PKUNZIP for MS-DOS, but in many cases the program
options or default behaviors differ.
ARGUMENTS
- file[.zip]
-
Path of the ZIP archive(s). If the file specification is a wildcard,
each matching file is processed in an order determined by the operating
system (or file system). Only the filename can be a wildcard; the path
itself cannot. Wildcard expressions are similar to Unix egrep(1)
(regular) expressions and may contain:
-
- *
-
matches a sequence of 0 or more characters
- ?
-
matches exactly 1 character
- [...]
-
matches any single character found inside the brackets; ranges are specified
by a beginning character, a hyphen, and an ending character. If an exclamation
point or a caret (`!' or `^') follows the left bracket, then the range of
characters within the brackets is complemented (that is, anything except
the characters inside the brackets is considered a match).
-
(Be sure to quote any character which might otherwise be interpreted or
modified by the operating system, particularly under Unix and VMS.) If no
matches are found, the specification is assumed to be a literal filename;
and if that also fails, the suffix .zip is appended. Note that
self-extracting ZIP files are supported, as with any other ZIP archive;
just specify the .exe suffix (if any) explicitly.
- [file(s)]
-
An optional list of archive members to be processed, separated by spaces.
(VMS versions compiled with VMSCLI defined must delimit files with commas
instead. See -v in OPTIONS below.)
Regular expressions (wildcards) may be used to match multiple members; see
above. Again, be sure to quote expressions that would otherwise be expanded
or modified by the operating system.
- [-x xfile(s)]
-
An optional list of archive members to be excluded from processing.
Since wildcard characters match directory separators (`/'), this option
may be used to exclude any files which are in subdirectories. For
example, ``unzip foo *.[ch] -x */*'' would extract all C source files
in the main directory, but none in any subdirectories. Without the -x
option, all C source files in all directories within the zipfile would be
extracted.
- [-d exdir]
-
An optional directory to which to extract files. By default, all files
and subdirectories are recreated in the current directory; the -d
option allows extraction in an arbitrary directory (always assuming one
has permission to write to the directory). This option need not appear
at the end of the command line; it is also accepted immediately after the
zipfile specification, or between the file(s) and the -x
option. The option and directory may
be concatenated without any white space between them, but note that this
may cause normal shell behavior to be suppressed. In particular,
``-d ~'' (tilde) is expanded by Unix C shells into the name
of the user's home directory, but ``-d~'' is treated as a
literal subdirectory ``~'' of the current directory.
OPTIONS
Note that, in order to support obsolescent hardware, unzip's usage
screen is limited to 22 or 23 lines and should therefore be considered a
reminder of the basic unzip syntax rather than an exhaustive list
of all possible flags.
- -Z
-
zipinfo(1L) mode. If the first option on the command line is -Z,
the remaining options are taken to be zipinfo(1L) options. See the
appropriate manual page for a description of these options.
- -c
-
extract files to stdout/screen (``CRT''). This option is similar to the
-p option except that the name of each file is printed as it is
extracted, the -a option is allowed, and ASCII-EBCDIC conversion
is automatically performed if appropriate. This option is not listed in
the unzip usage screen.
- -f
-
freshen existing files, i.e., extract only those files which
already exist on disk and which are newer than the disk copies. By
default unzip queries before overwriting, but the -o option
may be used to suppress the queries. Note that under many operating systems,
the TZ (timezone) environment variable must be set correctly in order for
-f and -u to work properly (under Unix the variable is usually
set automatically). The reasons for this are somewhat subtle but
have to do with the differences between DOS-format file times (always local
time) and Unix-format times (always in GMT) and the necessity to compare the
two. A typical TZ value is ``PST8PDT'' (US Pacific time with automatic
adjustment for Daylight Savings Time or ``summer time'').
- -l
-
list archive files (short format). The names, uncompressed file sizes and
modification dates and times of the specified files are printed, along
with totals for all files specified. In addition, the zipfile comment and
individual file comments (if any) are displayed. If a file was archived
from a single-case file system (for example, the old MS-DOS FAT file system)
and the -L option was given, the filename is converted to lowercase
and is prefixed with a caret (^).
- -p
-
extract files to pipe (stdout). Nothing but the file data is sent to
stdout, and the files are always extracted in binary format, just as they
are stored (no conversions).
- -t
-
test archive files. This option extracts each specified file in memory
and compares the CRC (cyclic redundancy check, an enhanced checksum) of
the expanded file with the original file's stored CRC value.
- -u
-
update existing files and create new ones if needed. This option performs
the same function as the -f option, extracting (with query) files
which are newer than those with the same name on disk, and in addition it
extracts those files which do not already exist on disk. See -f
above for information on setting the timezone properly.
- -v
-
be verbose or print diagnostic version info. This option has evolved and
now behaves as both an option and a modifier. As an option it has two
purposes: when a zipfile is specified with no other options, -v
lists archive files verbosely, adding to the -l info the compression
method, compressed size, compression ratio and 32-bit CRC. When no zipfile
is specified (that is, the complete command is simply ``unzip -v''), a
diagnostic screen is printed. In addition to the normal header with release
date and version, unzip lists the home Info-ZIP ftp site and where to
find a list of other ftp and non-ftp sites; the target operating system for
which it was compiled, as well as (possibly) the hardware on which it was
compiled, the compiler and version used, and the compilation date; any special
compilation options which might affect the program's operation (see also
DECRYPTION below); and any options stored in environment variables
which might do the same (see ENVIRONMENT OPTIONS below). As a
modifier it works in conjunction with other options (e.g., -t) to
produce more verbose or debugging output; this is not yet fully implemented
but will be in future releases.
- -z
-
display only the archive comment.
MODIFIERS
- -a
-
convert text files. Ordinarily all files are extracted exactly as they
are stored (as ``binary'' files). The -a option causes files identified
by zip as text files (those with the `t' label in zipinfo
listings, rather than `b') to be automatically extracted as such, converting
line endings, end-of-file characters and the character set itself as necessary.
(For example, Unix files use line feeds (LFs) for end-of-line (EOL) and
have no end-of-file (EOF) marker; Macintoshes use carriage returns (CRs)
for EOLs; and most PC operating systems use CR+LF for EOLs and control-Z for
EOF. In addition, IBM mainframes and the Michigan Terminal System use EBCDIC
rather than the more common ASCII character set, and NT supports Unicode.)
Note that zip's identification of text files is by no means perfect; some
``text'' files may actually be binary and vice versa. unzip therefore
prints ``[text]'' or ``[binary]'' as a visual check for each file
it extracts when using the -a option. The -aa option forces
all files to be extracted as text, regardless of the supposed file type.
- -b
-
treat all files as binary (no text conversions). This is a shortcut for
---a.
- -C
-
match filenames case-insensitively. unzip's philosophy is ``you get
what you ask for'' (this is also responsible for the -L/-U
change; see the relevant options below). Because some filesystems are fully
case-sensitive (notably those under the Unix operating system) and because
both ZIP archives and unzip itself are portable across platforms,
unzip's default behavior is to match both wildcard and literal filenames
case-sensitively. That is, specifying ``makefile'' on the command line
will only match ``makefile'' in the archive, not ``Makefile'' or
``MAKEFILE'' (and similarly for wildcard specifications). Since this does
not correspond to the behavior of many other operating/file systems (for
example, OS/2 HPFS which preserves mixed case but is not sensitive to it),
the -C option may be used to force all filename matches to be
case-insensitive. In the example above, all three files would then match
``makefile'' (or ``make*'', or similar). The -C option
affects files in both the normal file list and the excluded-file list (xlist).
- -j
-
junk paths. The archive's directory structure is not recreated; all files
are deposited in the extraction directory (by default, the current one).
- -L
-
convert to lowercase any filename originating on an uppercase-only operating
system or filesystem. (This was unzip's default behavior in releases
prior to 5.11; the new default behavior is identical to the old behavior with
the -U option, which is now obsolete and will be removed in a future
release.) Depending on the archiver, files archived under single-case
filesystems (VMS, old MS-DOS FAT, etc.) may be stored as all-uppercase names;
this can be ugly or inconvenient when extracting to a case-preserving
filesystem such as OS/2 HPFS or a case-sensitive one such as under
Unix. By default unzip lists and extracts such filenames exactly as
they're stored (excepting truncation, conversion of unsupported characters,
etc.); this option causes the names of all files from certain systems to be
converted to lowercase.
- -n
-
never overwrite existing files. If a file already exists, skip the extraction
of that file without prompting. By default unzip queries before
extracting any file which already exists; the user may choose to overwrite
only the current file, overwrite all files, skip extraction of the current
file, skip extraction of all existing files, or rename the current file.
- -o
-
overwrite existing files without prompting. This is a dangerous option, so
use it with care. (It is often used with -f, however.)
- -q
-
perform operations quietly (-qq = even quieter). Ordinarily unzip
prints the names of the files it's extracting or testing, the extraction
methods, any file or zipfile comments which may be stored in the archive,
and possibly a summary when finished with each archive. The -q[q]
options suppress the printing of some or all of these messages.
- -s
-
[OS/2, NT, MS-DOS] convert spaces in filenames to underscores. Since all PC
operating systems allow spaces in filenames, unzip by default extracts
filenames with spaces intact (e.g., ``EA DATA. SF''). This can be
awkward, however, since MS-DOS in particular does not gracefully support
spaces in filenames. Conversion of spaces to underscores can eliminate the
awkwardness in some cases.
- -U
-
(obsolete; to be removed in a future release) leave filenames uppercase if
created under MS-DOS, VMS, etc. See -L above.
- -V
-
retain (VMS) file version numbers. VMS files can be stored with a version
number, in the format file.ext;##. By default the ``;##'' version
numbers are stripped, but this option allows them to be retained. (On
filesystems which limit filenames to particularly short lengths, the version
numbers may be truncated or stripped regardless of this option.)
- -X
-
[VMS] restore owner/protection info (may require system privileges). Ordinary
file attributes are always restored, but this option allows UICs to be restored
as well. [The next version of unzip will support Unix UID/GID info as
well, and possibly NT permissions.]
- -$
-
[MS-DOS, OS/2, NT, Amiga] restore the volume label if the extraction medium is
removable (e.g., a diskette). Doubling the option (-$$) allows fixed
media (hard disks) to be labelled as well. By default, volume labels are
ignored.
ENVIRONMENT OPTIONS
unzip's default behavior may be modified via options placed in
an environment variable. This can be done with any option, but it
is probably most useful with the -a, -L, -C, -q,
-o, or -n modifiers: make unzip auto-convert text
files by default, make it convert filenames from uppercase systems to
lowercase, make it match names case-insensitively, make it quieter,
or make it always overwrite or never overwrite files as it extracts
them. For example, to make unzip act as quietly as possible, only
reporting errors, one would use one of the following commands:
Environment options are, in effect, considered to be just like any other
command-line options, except that they are effectively the first options
on the command line. To override an environment option, one may use the
``minus operator'' to remove it. For instance, to override one of the
quiet-flags in the example above, use the command
The first hyphen is the normal
switch character, and the second is a minus sign, acting on the q option.
Thus the effect here is to cancel one quantum of quietness. To cancel
both quiet flags, two (or more) minuses may be used:
(the two are equivalent). This may seem awkward
or confusing, but it is reasonably intuitive: just ignore the first
hyphen and go from there. It is also consistent with the behavior of
Unix nice(1).
As suggested by the examples above, the default variable names are UNZIP_OPTS
for VMS (where the symbol used to install unzip as a foreign command
would otherwise be confused with the environment variable), and UNZIP
for all other operating systems. For compatibility with zip(1L),
UNZIPOPT is also accepted (don't ask). If both UNZIP and UNZIPOPT
are defined, however, UNZIP takes precedence. unzip's diagnostic
option (-v with no zipfile name) can be used to check the values
of all four possible unzip and zipinfo environment variables.
The timezone variable (TZ) should be set according to the local timezone
in order for the -f and -u to operate correctly. See the
description of -f above for details. This variable may also be
necessary in order for timestamps on extracted files to be set correctly.
DECRYPTION
Encrypted archives are fully supported by Info-ZIP software, but due to
United States export restrictions, the encryption and decryption sources
are not packaged with the regular unzip and zip distributions.
Since the crypt sources were written by Europeans, however, they are
freely available at sites throughout the world; see the file ``Where'' in
any Info-ZIP source or binary distribution for locations both inside and
outside the US.
Because of the separate distribution, not all compiled versions of unzip
support decryption. To check a version for crypt support, either attempt to
test or extract an encrypted archive, or else check unzip's diagnostic
screen (see the -v option above) for ``[decryption]'' as one of
the special compilation options.
There are no runtime options for decryption; if a zipfile member is encrypted,
unzip will prompt for the password without echoing what is typed.
unzip continues to use the same password as long as it appears to be
valid; it does this by testing a 12-byte header. The correct password will
always check out against the header, but there is a 1-in-256 chance that an
incorrect password will as well. (This is a security feature of the PKWARE
zipfile format; it helps prevent brute-force attacks which might otherwise
gain a large speed advantage by testing only the header.) In the case that
an incorrect password is
given but it passes the header test anyway, either an incorrect CRC will be
generated for the extracted data or else unzip will fail during the
extraction because the ``decrypted'' bytes do not constitute a valid
compressed data stream.
If the first password fails the header check on some file, unzip will
prompt for another password, and so on until all files are extracted. If
a password is not known, entering a null password (that is, just a carriage
return) is taken as a signal to skip all further prompting. Only unencrypted
files in the archive(s) will thereafter be extracted. (Actually that's not
quite true; older versions of zip(1L) and zipcloak(1L) allowed
null passwords, so unzip checks each encrypted file to see if the null
password works. This may result in ``false positives'' and extraction
errors, as noted above.)
Note that there is presently no way to avoid interactive decryption. This
is another security feature: plaintext passwords given on the command line
or stored in files constitute a risk because they may be seen by others.
Future releases may (under protest, with great disapproval) support such
shenanigans.
EXAMPLES
To use unzip to extract all members of the archive letters.zip
into the current directory and subdirectories below it, creating any
subdirectories as necessary:
To extract all members of letters.zip into the current directory only:
To test letters.zip, printing only a summary message indicating
whether the archive is OK or not:
To test all zipfiles in the current directory, printing only the
summaries:
(The backslash before the asterisk is only required if the shell expands
wildcards, as in Unix; double quotes could have been used instead, as in
the source examples below.) To extract to standard output all members of
letters.zip whose names end in .tex, auto-converting to the
local end-of-line convention and piping the output into more(1):
To extract the binary file paper1.dvi to standard output and pipe it
to a printing program:
To extract all FORTRAN and C source files--*.f, *.c, *.h, and Makefile--into
the /tmp directory:
(the double quotes are necessary only in Unix and only if globbing is turned
on). To extract all FORTRAN and C source files, regardless of case (e.g.,
both *.c and *.C, and any makefile, Makefile, MAKEFILE or similar):
To extract any such files but convert any uppercase MS-DOS or VMS names to
lowercase and convert the line-endings of all of the files to the local
standard (without respect to any files which might be marked ``binary''):
To extract only newer versions of the files already in the current
directory, without querying (NOTE: be careful of unzipping in one timezone a
zipfile created in another--ZIP archives to date contain no timezone
information, and a ``newer'' file from an eastern timezone may, in fact, be
older):
To extract newer versions of the files already in the current directory and
to create any files not already there (same caveat as previous example):
To display a diagnostic screen showing which unzip and zipinfo
options are stored in environment variables, whether decryption support was
compiled in, the compiler with which unzip was compiled, etc.:
In the last five examples, assume that UNZIP or UNZIP_OPTS is set to -q.
To do a singly quiet listing:
To do a doubly quiet listing:
(Note that the ``.zip'' is generally not necessary.) To do a standard
listing:
or
or
TIPS
The current maintainer, being a lazy sort, finds it very useful to define
a pair of aliases: tt for ``unzip -tq'' and ii for
``unzip -Z'' (or ``zipinfo''). One may then simply type
``tt zipfile'' to test an archive, something which is worth making a
habit of doing. With luck unzip will report ``No errors detected
in zipfile.zip,'' after which one may breathe a sigh of relief.
The maintainer also finds it useful to set the UNZIP environment variable
to ``-aL'' and is tempted to add ``-C'' as well. His ZIPINFO
variable is set to ``-z''.
DIAGNOSTICS
The exit status (or error level) approximates the exit codes defined by PKWARE
and takes on the following values, except under VMS:
-
- 0
-
normal; no errors or warnings detected.
- 1
-
one or more warning errors were encountered, but processing completed
successfully anyway. This includes zipfiles where one or more files
was skipped due to unsupported compression method or encryption with an
unknown password.
- 2
-
a generic error in the zipfile format was detected. Processing may have
completed successfully anyway; some broken zipfiles created by other
archivers have simple work-arounds.
- 3
-
a severe error in the zipfile format was detected. Processing probably
failed immediately.
- 4-8
-
unzip was unable to allocate memory for one or more buffers.
- 9
-
the specified zipfiles were not found.
- 10
-
invalid options were specified on the command line.
- 11
-
no matching files were found.
- 50
-
the disk is (or was) full during extraction.
- 51
-
the end of the ZIP archive was encountered prematurely.
VMS interprets standard Unix (or PC) return values as other, scarier-looking
things, so by default unzip always returns 0 (which reportedly gets
converted into a VMS status of 1--i.e., success). There are two compilation
options available to modify or expand upon this behavior: defining
RETURN_CODES results in a human-readable explanation of what the real
error status was (but still with a faked ``success'' exit value), while
defining RETURN_SEVERITY causes unzip to exit with a ``real'' VMS
status. The latter behavior will become the default in future
versions unless it is found to conflict with officially defined VMS codes.
The current mapping is as follows: 1 (success) for normal exit, 0x7fff0001
for warning errors, and (0x7fff000? + 16*normal_unzip_exit_status) for all
other errors, where the `?' is 2 (error) for unzip values 2 and 9-11,
and 4 (fatal error) for the remaining ones (3-8, 50, 51). Check the
``unzip -v'' output to see whether RETURN_SEVERITY was defined at
compilation time.
BUGS
When attempting to extract a corrupted archive, unzip may go into
an infinite loop and, if not stopped quickly enough, fill all available disk
space. Compiling with CHECK_EOF should fix this problem for all zipfiles,
but the option was introduced too late in the testing process to be made
the default behavior. Future versions will be robust enough to fail
gracefully on damaged archives. Check the ``unzip -v'' output to
see whether CHECK_EOF was defined during compilation.
[MS-DOS] When extracting or testing files from an archive on a defective
floppy diskette, if the ``Fail'' option is chosen from DOS's ``Abort, Retry,
Fail?'' message, unzip may hang the system, requiring a reboot. Instead,
press control-C (or control-Break) to terminate unzip.
Under DEC Ultrix, unzip will sometimes fail on long zipfiles (bad CRC,
not always reproducible). This is apparently due either to a hardware bug
(cache memory) or an operating system bug (improper handling of page faults?).
Dates and times of stored directories are not restored.
[OS/2] Extended attributes for existing directories are never updated. This
is a limitation of the operating system; unzip has no way to determine
whether the stored attributes are newer or older than the existing ones.
[VMS] When extracting to another directory, only the [.foo] syntax is
accepted for the -d option; the simple Unix foo syntax is
silently ignored (as is the less common VMS foo.dir syntax).
[VMS] When the file being extracted already exists, unzip's query only
allows skipping, overwriting or renaming; there should additionally be a
choice for creating a new version of the file. In fact, the ``overwrite''
choice does create a new version; the old version is not overwritten or
deleted.
SEE ALSO
funzip(1L), zip(1L), zipcloak(1L), zipgrep(1L),
zipinfo(1L), zipnote(1L), zipsplit(1L)
AUTHORS
The primary Info-ZIP authors (current zip-bugs workgroup) are: Jean-loup
Gailly (Zip); Greg R. Roelofs (UnZip); Mark Adler (decompression, fUnZip);
Kai Uwe Rommel (OS/2); Igor Mandrichenko and Hunter Goatley (VMS); John Bush
and Paul Kienitz (Amiga); Antoine Verheijen (Macintosh); Chris Herborth
(Atari); Henry Gessau (NT); Karl Davis, Sergio Monesi and Evan Shattock
(Acorn Archimedes); and Robert Heath (Windows). The author of the original
unzip code upon which Info-ZIP's is based was Samuel H. Smith; Carl Mascott
did the first Unix port; and David P. Kirschbaum organized and led Info-ZIP
in its early days. The full list of contributors to UnZip has grown quite
large; please refer to the CONTRIBS file in the UnZip source distribution
for a relatively complete version.
VERSIONS
- v1.2 15 Mar 89
-
Samuel H. Smith
- v2.0 9 Sep 89
-
Samuel H. Smith
- v2.x fall 1989
-
many Usenet contributors
- v3.0 1 May 90
-
Info-ZIP (DPK, consolidator)
- v3.1 15 Aug 90
-
Info-ZIP (DPK, consolidator)
- v4.0 1 Dec 90
-
Info-ZIP (GRR, maintainer)
- v4.1 12 May 91
-
Info-ZIP
- v4.2 20 Mar 92
-
Info-ZIP (zip-bugs subgroup, GRR)
- v5.0 21 Aug 92
-
Info-ZIP (zip-bugs subgroup, GRR)
- v5.01 15 Jan 93
-
Info-ZIP (zip-bugs subgroup, GRR)
- v5.1 7 Feb 94
-
Info-ZIP (zip-bugs subgroup, GRR)
- v5.11 2 Aug 94
-
Info-ZIP (zip-bugs subgroup, GRR)
- v5.12 28 Aug 94
-
Info-ZIP (zip-bugs subgroup, GRR)
Index
- NAME
-
- SYNOPSIS
-
- DESCRIPTION
-
- ARGUMENTS
-
- OPTIONS
-
- MODIFIERS
-
- ENVIRONMENT OPTIONS
-
- DECRYPTION
-
- EXAMPLES
-
- TIPS
-
- DIAGNOSTICS
-
- BUGS
-
- SEE ALSO
-
- AUTHORS
-
- VERSIONS
-
This document was created by
man2html,
using the manual pages.
Time: 11:36:25 GMT, October 09, 2024